home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Creation Date: Feb, 2000
- // Author: bb
- //
- // Procedure Name:
- // doCreateSubcharacterArgList
- //
- // Description:
- // Create a new sub character
- //
- // Input Arguments:
- // $version: The version of this option box. Used to know how to
- // interpret the $args array.
- // "1" : $name
- //
- // $args
- // Version 1
- // [0] $name : name to give the new character
- // [1] $excludeTranslate : exclude translate attrs when creating char
- // [2] $excludeRotate : exclude rotate attrs when creating char
- // [3] $excludeScale : exclude scale attrs when creating char
- // [4] $excludeVis : exclude visibility attrs when creating char
- // [5] $excludeDynamic : exclude dynamic attrs when creating char
- // [6] $channelBox : create based on channel box selections
- //
- // Return Value:
- // New subcharacter name
- //
-
- global proc string doCreateSubcharacterArgList( string $version,
- string $args[] )
- {
- string $name = $args[0];
- int $excludeTranslate = $args[1];
- int $excludeRotate = $args[2];
- int $excludeScale = $args[3];
- int $excludeVisibility = $args[4];
- int $excludeDynamic = $args[5];
- int $useChannelBox = $args[6];
-
- // See if there is a current character
- //
- string $currChar[] = `currentCharacters`;
- if (size($currChar) == 0) {
- error "Must have a current character.";
- return "";
- }
- if (size($currChar) > 1) {
- error "Must have a single current character.";
- return "";
- }
-
- string $currentSelection[] = `ls -selection`;
- string $currentSelectionTypes[] = `ls -selection -st`;
- string $attrs[];
- string $attrsInCharacter[];
- if ($useChannelBox) {
- $attrs = `selectedChannelBoxPlugs`;
- if (size($attrs) == 0) {
- error("No attributes were selected in the channel box.");
- return "";
- }
- } else {
- int $excludeTransform = $excludeTranslate + $excludeRotate + $excludeVisibility + $excludeScale;
- int $selCount = size($currentSelection);
- int $ii;
- for ($ii = 0; $ii < $selCount; $ii++) {
- string $sel = $currentSelection[$ii];
- string $selType = $currentSelectionTypes[$ii*2+1];
-
- if ($sel == $currChar[0]) {
- warning("Skipping '"+$sel+"'. Cannot make a character a subcharacter of itself.");
- continue;
- }
-
- string $selName = $sel;
- if ($selType != "float3" && $selType != "double3") {
- if (nodeType($sel) != $selType) {
- warning("Skipping '"+$sel+"'. Unless you use the channel box option, only selected nodes can be made into subcharacters.");
- continue;
- }
- } else {
- // For point-type attributes (cv's and vertices), the
- // attribute name differs from the component name. Strip off
- // the component name.
- //
- string $buffer[];
- int $result = tokenize($sel,".",$buffer);
- $selName = $buffer[0];
-
- // components may also be tweaks ... take that into
- // account as well
- //
- string $isControlPoint[];
- $isControlPoint = `ls -type controlPoint $selName`;
- if (!size($isControlPoint)) {
- $isControlPoint = `listRelatives -ni -s -typ controlPoint $selName`;
- }
- if (size($isControlPoint)) {
- string $tmp[];
- $tmp = `listConnections ($isControlPoint[0]+".tweakLocation")`;
- if (size($tmp)) {
- $selName = $tmp[0];
- }
- }
- }
-
- if (nodeType($sel) == "character") {
- warning("Skipping '"+$sel+"'. Select nodes or attributes that you want to put into the subcharacter. Do not select characters.");
- continue;
- }
-
- string $keyableAttrs[] = `listAttr -m -k $sel`;
- for ($at in $keyableAttrs) {
-
- // build a list of the attributes in the character
- //
- if ($excludeDynamic) {
- string $userDefined[] = `listAttr -ud ($selName+"."+$at)`;
- if (size($userDefined) > 0) {
- continue;
- }
- }
-
- if ($excludeTransform == 0) {
- $attrs[size($attrs)] = ($selName+"."+$at);
- continue;
- }
-
- string $isTransform[] = `ls -type transform $selName`;
- if (size($isTransform) == 0) {
- $attrs[size($attrs)] = ($selName+"."+$at);
- continue;
- }
-
- if ($excludeVisibility && $at == "visibility") {
- continue;
- }
- if ($excludeScale &&
- ($at == "scaleX" || $at == "scaleY" || $at == "scaleZ"))
- continue;
- if ($excludeTranslate &&
- ($at == "translateX" || $at == "translateY" ||
- $at == "translateZ")) {
- continue;
- }
- if ($excludeRotate &&
- ($at == "rotateX" || $at == "rotateZ" || $at == "rotateY")) {
- continue;
- }
-
- $attrs[size($attrs)] = ($selName+"."+$at);
- }
- }
- if (size($currentSelection) > 0 && (size($attrs) == 0)) {
- error("No valid subcharacter objects were selected.");
- return "";
- }
- }
-
- int $cc;
- for ($cc = 0; $cc < size($attrs); $cc++) {
- if (nodeType($attrs[$cc]) == "character") {
- string $dstConn[] = `listConnections -s 0 -d 1 -p 1 $attrs[$cc]`;
- for ($dst in $dstConn) {
- string $dp;
- catch($dp = `character -q -cp $dst`);
- if ($dp == $attrs[$cc]) {
- $attrs[$cc] = $dst;
- }
- }
- }
- if (`character -isMember $currChar[0] $attrs[$cc]`) {
- $attrsInCharacter[size($attrsInCharacter)] = $attrs[$cc];
- }
- }
-
- // Build the create character command
- //
- $cmd = ( "character -empty -name \"" + $name + "\";");
-
- // Create the new character
- //
- string $character = eval( $cmd );
-
- $cmd = ( "character -edit -add "+$currChar[0]+" "+$character );
- eval($cmd);
-
- if (size($attrs)) {
- $cmd = ("character -edit -forceElement "+$character);
- for ($at in $attrs) {
- $cmd += (" "+$at);
- }
- eval($cmd);
- }
-
- return $character;
- }
-